﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Microsoft.Phone.Controls;

namespace RadarGlobalPro.Class
{
    class ContextMenuController
    {
        ContextMenu myMenu = new ContextMenu();

        Dictionary<string, MenuItem> MenuItems { get; set; }

        public void Show()
        {
            if(myMenu.Items.Count>0)
            myMenu.IsOpen = true;
        }
        public void AddControlHandler(object Control)
        {
            ContextMenuService.SetContextMenu((DependencyObject)Control, myMenu);
        }
        public void Add(string Text, bool isEnabled, RoutedEventHandler e)
        {
            if (MenuItems == null)
            {
                MenuItems = new Dictionary<string, MenuItem>();
            }

            if (MenuItems.ContainsKey(Text)) { return; }

            MenuItem menuitem = new MenuItem()
            {
                Header = Text,
                IsEnabled = isEnabled
            };
            menuitem.Click+=e;

            MenuItems.Add(Text, menuitem);
        }
        public void ShowMenuItems(params string[] MenuItemText)
        {
            foreach (string text in MenuItemText)
            {
                if (!myMenu.Items.Contains(MenuItems[text]))
                {
                   myMenu.Items.Add(MenuItems[text]);
                }
            }
            Show();
        }
        public void RemoveMenuItems(params string[] MenuItemText)
        {
            foreach (string text in MenuItemText)
            {
                if (myMenu.Items.Contains(MenuItems[text]))
                {
                    myMenu.Items.Remove(MenuItems[text]);
                }
            }
        }
        /// <summary>
        /// Clear all menu items in the Menu context
        /// </summary>
        public void RemoveMenuItems()
        {
            myMenu.Items.Clear();
        }
    }
}
